package com.test.langchain4j.controller;

import com.test.langchain4j.service.ChatPersistenceAssistant;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 2025/8/1 16:12
 * @modifiedBy:
 * @version: 1.0
 */
@RestController
@Slf4j
public class ChatPersistenceController {
  @Resource private ChatPersistenceAssistant chatPersistenceAssistant;

  // http://localhost:9010/chatpersistence/redis
  @GetMapping(value = "/chatpersistence/redis")
  public String testChatPersistence() {
    chatPersistenceAssistant.chat(1L, "你好, 我的名字是redis");
    chatPersistenceAssistant.chat(2L, "你好, 我的名字是nacos");

    String chat = chatPersistenceAssistant.chat(1L, "我的名字是什么？");
    log.info("User ID: {}, Message: {}, Response: {}", 1L, "我的名字是什么？", chat);

    chat = chatPersistenceAssistant.chat(2L, "我的名字是什么？");
    log.info("User ID: {}, Message: {}, Response: {}", 2L, "我的名字是什么？", chat);
    return "test chat persistence success : " + chat + "<br> \n\n" + "请查看日志输出，验证是否正确获取了用户的聊天记录。";
  }
}
